package com.cmw.controller.web;


import javax.annotation.Resource;
import com.cmw.core.base.annotation.Description;
import com.alibaba.fastjson.JSONObject;
import com.cmw.core.base.exception.ServiceException;
import com.cmw.core.base.exception.UtilException;
import com.cmw.core.util.BeanUtil;
import com.cmw.core.util.FastJsonUtil;
import com.cmw.core.util.PageHandler;
import com.cmw.core.util.StringHandler;
import com.cmw.service.inter.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.cmw.entity.LoginOutLogEntity;
import com.cmw.service.inter.LoginOutLogService;


/**
 * 退出登录日志  ACTION类
 * @author 程明卫
 * @date 2017-06-19 17:57:43
 */
@Description(remark="退出登录日志ACTION",createDate="2017-06-19 17:57:43",author="程明卫")
@RestController
@RequestMapping({"/loginoutlog"})
public class LoginOutLogController extends BaseController{
	@Resource(name="loginOutLogService")
	private LoginOutLogService loginOutLogService;
	
	 /**
     * 跳转主页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/home")
    public JSONObject home(HttpServletRequest request, HttpServletResponse response, Map<String,Object> map) throws Exception{
       List<LoginOutLogEntity> list = loginOutLogService.getListAll();
       return PageHandler.getJson(list);
    }

    /**
     * 跳转列表页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/list")
    public JSONObject list(HttpServletRequest request, HttpServletResponse response){
        List<LoginOutLogEntity> list = loginOutLogService.getListAll();
        return PageHandler.getJson(list);
    }

    /**
     * 跳转详细页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/info") 
    public JSONObject info(HttpServletRequest request, HttpServletResponse response){
        Long id = PageHandler.getLVal(request ,"id");
        if(StringHandler.isValidObj(id)) throw new ServiceException(ServiceException.BREED_IS_NULL);
        LoginOutLogEntity obj = loginOutLogService.get(id);
        return PageHandler.getJson(obj);
    }

    /**
     * 保存数据
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/save")
    public JSONObject save(HttpServletRequest request, HttpServletResponse response) throws Exception{
        LoginOutLogEntity entity = BeanUtil.copyValue(LoginOutLogEntity.class, request);
        loginOutLogService.insert(entity);
        return PageHandler.getSuccessJson();
    }

    /**
     * 移除数据
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/remove")
    public JSONObject remove(HttpServletRequest request, HttpServletResponse response) throws Exception{
        Long id = PageHandler.getLVal(request, "id");
        loginOutLogService.delete(id);
        return PageHandler.getSuccessJson();
    }
	
}
